package guoanmaker.operator.business.repository;

import java.util.List;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.transaction.annotation.Transactional;

import guoanmaker.operator.business.model.OperatorTrademarkAccount;

public interface OperatorTrademarkAccountRepository extends JpaRepository<OperatorTrademarkAccount, String>,JpaSpecificationExecutor<OperatorTrademarkAccount>{

	@Query("select t from OperatorTrademarkAccount t where t.searchCount > 0")
	public List<OperatorTrademarkAccount> findAllSearchAccount();

	@Query("select t from OperatorTrademarkAccount t where t.infoCount > 0")
	public List<OperatorTrademarkAccount> findAllInfoAccount();
	
	
	@Modifying
	@Transactional
	@Query("update OperatorTrademarkAccount set searchCount = searchCount - 1 where id = ?1")
	public void divAccountSearchCount(String id);
	
	@Modifying
	@Transactional
	@Query("update OperatorTrademarkAccount set infoCount = infoCount - 1 where id = ?1")
	public void divAccountInfoCount(String id);
	
	@Modifying
	@Transactional
	@Query("update OperatorTrademarkAccount set searchCount = ?2 where id = ?1")
	public void resetAccountSearchCount(String id , Integer count);
	
	@Modifying
	@Transactional
	@Query("update OperatorTrademarkAccount set infoCount = ?2 where id = ?1")
	public void resetAccountInfoCount(String id , Integer count);
}
